/**
 * Created by Administrator on 2015/12/21.
 */
 $(document).ready(function(){

    /*nav*/
    var $display = $('.hover-display');
    var $displayImg = $('.display-img');
    $displayImg.each(function(index){
        var $this = $(this);
        $this.mouseover(function(){
            $display.removeClass("display");
            $display.eq(index).addClass("display");
        })
        $this.mouseout(function(){
            $display.removeClass("display");
        }); 
    });

    var $downloadDisplay = $('.download-display');
    var $resourceImgDiv = $('.resource-img');
    $resourceImgDiv.each(function(index){
        var $this = $(this);
        $this.mouseover(function(){
            $downloadDisplay.removeClass("d-display");
            $downloadDisplay.eq(index).addClass("d-display");
        })
        $this.mouseout(function(){
            $downloadDisplay.removeClass("d-display");
        }); 
    });

    $(window).scroll(function() {       //页面滚动显示元素。
        if($(window).scrollTop()>=1000){
            $(".contact-teacher").fadeIn(500);
            $(".back-to-top").fadeIn(500);
        }else{
            $(".contact-teacher").fadeOut(300);
            $(".back-to-top").fadeOut(300);
        }
    })
    //回到顶部
    $('#back-to-top').click(function () {
        $('html,body').animate({
            scrollTop : '0px'
        }, 1000);//返回顶部所用的时间 
    });
    //Menu
    $('.dropdown-toggle').dropdown('toggle');
    $('.menu-block').removeClass('open');

    //手机版人物滚动
    var ifMobile=!!navigator.userAgent.match(/AppleWebKit.*Mobile.*/);
    var studentsWidth=$('.students').width();
    var $exprienceBox=$('.exprience-box');
    var $scrollBlock=$('.students .scroll-block');
    var scrollBarWidth=$('.scroll-bar').width();
    var $scrollSlider=$('.scroll-slider');
    if(ifMobile){
        $(".scroll-bar").show();
        var exprienceBoxWidth=$exprienceBox.width()+16;
        var scrollBlockWidth=exprienceBoxWidth * ($exprienceBox.length);
        var scrollsliderWidth=exprienceBoxWidth/scrollBlockWidth*100+"%";

        $scrollBlock.width(scrollBlockWidth);
        $scrollSlider.width(scrollsliderWidth);
        // $scrollBlock.on('touchstart',function(e){
        //     e=e.originalEvent.touches[0];//获取对应触摸对象
        //     var px=e.pageX;
        //     var left=$scrollBlock.position().left;
        //     console.log(left);
            
        //     $(this).on('touchmove',function(e){
        //         e=e.originalEvent.changedTouches[0];//获取对应触摸对象
        //         var movex=e.pageX;
        //         var newLeft=movex-px+left;
        //         // var scrollSliderLeft=Math.abs(newLeft)/(scrollBlockWidth-studentsWidth)*100-exprienceBoxWidth/scrollBlockWidth*100+"%";
        //         var scrollSliderLeft=-(1-exprienceBoxWidth/scrollBlockWidth)*(newLeft+12)*100/(scrollBlockWidth-exprienceBoxWidth)+"%";
        //         $scrollSlider.css("left",scrollSliderLeft);
        //         $scrollBlock.css("left",newLeft);
                
        //     });
        // });        
    }
});